<!doctype html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>参考数据比例</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">

    <script src="http://i.gtimg.cn/qzone/biz/gdt/lib/jquery/jquery-2.1.4.js?max_age=31536000"></script>

    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script src='https://cdn.bootcss.com/jquery.form/4.2.2/jquery.form.min.js'></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/aliyun-oss-sdk.min.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
    <div class="easyui-panel" style="border: none;">
        <div class="nav" id="nav"></div>
        <div class="easyui-panel" style="border:none;">
            <form id="ff">
                <div style="margin-bottom:20px;">
                    <label class="item-label">年份：</label>
                    <input type="text" id="year" name="year" class="easyui-combobox" style="width: 100px;"/>
                    <span id="weekLabel">
                            <label class="item-label">周度：</label>
                        	<input type="text" id="week" name="week" class="easyui-combobox" style="width: 100px;"/>
                        </span>
                    <label class="item-label">品类：</label>
                    <input type="text" id="categories" class="easyui-combobox" style="width:174px;" name="categories" data-options="multiple:true" />
                    <label class="item-label">固定系数：</label>
                    <input  type="text" name="jdZb" id="reg_num"  class="easyui-textbox " prompt="天猫/京东比值"  style="width:100px;"value="" validType="length[0,24]"/>


                    <label class="item-label">状态：</label>
                    <input id="entityStatus" class="easyui-switchbutton" checked style="width:80px;height:30px;" onText="启用" offText="禁用"  >

                    <a class="easyui-linkbutton c8" href="javascript:void(0);" onclick="OnlineCount()" style="width:80px;margin-left: 10px;">处理销量</a>&nbsp;&nbsp;
                    <a class="easyui-linkbutton c8" href="javascript:void(0);" onclick="jsReference()" style="width:80px;margin-left: 10px;">重算系数</a>&nbsp;&nbsp;
                    <a class="easyui-linkbutton c8" href="javascript:void(0);" onclick="xsReset()" style="width:80px;margin-left: 10px;">系数重置</a>&nbsp;&nbsp;

                    <a href="javascript:void(0);" class="easyui-linkbutton c8" onclick="searchBy()" style="width:80px;margin-left: 40px;">查询</a>
                </div>
                <div style="margin-bottom:20px;">
                    <label class="item-label">渠道码：</label>
                    <input type="text" id="channelSelect" name="channelCode" class="easyui-textbox" style="width:100px;"/>
                    <label class="item-label">调整系数：</label>
                    <input  type="text" name="xs" id="ztxs"  class="easyui-textbox " prompt="以现销量为基础"  style="width:100px;"value="" validType="length[0,24]"/>

                    <label class="item-label">数据状态：</label>
                    <select id="comboSyayus" name="comboSyayus" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:120px;" prompt="比较符">
                        <option value="ALL"  selected = "selected" >不限制</option>
                        <option value="COMBO">套餐</option>
                        <option value="NOCOMBO">非套餐</option>
                    </select>
                    <label class="item-label">品牌：</label>
                    <select id="brandSelect" name="brandCode" class="easyui-combobox" style="width:100px;"></select>
                    <label class="item-label" style="width: 50px;margin-left: 20px;">规格：</label>
                    <input type="text" name="propCode" id="propCode" class="easyui-combobox" data-options="panelHeight:'150'" style="width:100px;" />
                    <select name="comparator" id="comparator"  class="easyui-combobox" data-options="panelHeight:'150'" style="width:100px;"   >
                        <option value="EQUAL">=</option>
                        <option value="GREAT">></option>
                        <option value="GREAT_EQUAL">>=</option>
                        <option value="LITTLE"><</option>
                        <option value="LITTLE_EQUAL"><=</option>
                        <option value="NOT_EQUAL"><></option>
                        <option value="CONTAIN">包含</option>
                    </select>
                    <div style="display: inline-block" id="metadatavalue" >
                    </div>

                    <a class="easyui-linkbutton c8" href="javascript:void(0);" onclick="clCount()" style="width:80px;margin-left: 50px;">修改销量</a>&nbsp;&nbsp;
                    <a class="easyui-linkbutton c8" href="javascript:void(0);" onclick="restoreCount()" style="width:80px;margin-left: 50px;">撤销销量</a>&nbsp;&nbsp;

                </div>
            </form>
            <div id="upmall" class="easyui-window upload-wrapper" title="上传文件" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:400px;height:260px;padding:10px;">
                <form id="file_formr" action="" enctype="multipart/form-data"method="post">
                    <div style="margin-bottom:20px;margin-top: 20px;">
                        <input type="file" multiple="multiple" name="file" id="file_reference" class="item-label"style="margin-top: 33px;margin-left: 64px;width: 280px;" />
                    </div>
                    <div style="margin-bottom:20px;margin-top: 60px;text-align:center">
                        <input type="button" value="文件上传" name="Submit" id='subr' style="height: 40px;width: 100px;font-size: 18px;" class="easyui-linkbutton c8">
                    </div>
                </form>
            </div>
            <div id="referencejg" class="easyui-window upload-wrapper" title="上传结果" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:1200px;height: 430px;padding:10px;">
                <div><li>信息为：</li><span id="messagetext"></span></div>
                <div style="margin-left: 550px;"><button class="easyui-linkbutton c8" style="width: 100px;margin-top: 130px;" onclick="clickHandler()">确定</button></div>
            </div>
        </div>
        <div class="table-wrapper">
            <table id="datagrid" data-options="fitColumns:true,scrollBarSize:0">
                <thead>
                <tr>
                    <th data-options="field:'categoryName',align:'center'" width="80"formatter="formatCategory">品类名称</th>
                    <th data-options="field:'originalCategory',align:'center'" width="120">原始品类</th>
                    <th data-options="field:'brandName',align:'center'" width="80"formatter="formatBrand">品牌名称</th>
                    <th data-options="field:'originalBrand',align:'center'" width="130">原始品牌</th>
                    <th data-options="field:'proportion',align:'center'" width="100">比例系数</th>
                    <th data-options="field:'avcCount',align:'center'" width="100">avc销量</th>
                    <th data-options="field:'jdsqCount',align:'center'" width="100">京东上期销量</th>
                    <th data-options="field:'jdbqCount',align:'center'" width="100">京东本期销量</th>
                    <th data-options="field:'tmCount',align:'center'" width="100">天猫本期销量</th>
                    <th data-options="field:'jdZb',align:'center'" width="80">京东参考占比</th>
                    <th data-options="field:'dealWIth',align:'center',formatter:dealWIth"  width="60">是否已处理</th>
                    <th data-options="field:'proportionStatus',align:'center',formatter:proportionStatus"  width="65">系数是否计算</th>
                    <th data-options="field:'operateUser',align:'center'" width="70">操作人</th>
                    <th data-options="field:'entityStatus',align:'center',formatter:statusFormatter" width="40">状态</th>
                    <th data-options="field:'action',align:'center',formatter:actions" width="80">操作</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    var id;
    function initPage(){
        searchBy(1,100);
    }
    $(function(){
        id=getQueryParameter("id");
        initMonthWeek("monthLabel","weekLabel");
        initBrandSelect("brandSelect");
        initCategorySelect("categories",function (code) {
            initModelSearchSelect("propCode","metadatavalue",code);
        });
        var height = $(window).height();
        var nav_height = $("#nav")._outerHeight();
        var ff_height = $("#ff").height();
        var table_height = height-nav_height-ff_height-40;
        $("#datagrid").css("max-height",table_height);
        $("#datagrid").datagrid({
            rownumbers:true,
            pagination:true,
            idField:"id",
            checkOnSelect:false,
            toolbar:[{
                text:'添加数据',
                handler:function(){
                    window.parent.addTab("添加数据","/webapp/pages/channel/avcReference/add.html");
                }
            },'-',{
                text:'上传数据',
                handler:function(){
                    $("#upmall").window("open");
                }
            }]
        }).datagrid("getPager").pagination({
            onSelectPage:searchBy
        });
        initPage();
        $("#reg_num").textbox('textbox').bind('keyup', function(e){
            $("#reg_num").textbox('setValue', $(this).val().replace(/[^\0-9\.\/]/ig,''));
        });

    });

    function dealWIth(val,row){
        if(row.dealWIth){
            return "是";
        }else{
            return "否"
        }
    }
    function proportionStatus(val,row){
        if(row.proportionStatus){
            return "是";
        }else{
            return "否"
        }
    }

    function searchBy(page,size) {
        var dtd = $.Deferred();
        var data = getFormData(document.getElementById("ff"));
        if (!isMonthType() && !data.week) {
            data.week = window.parent.timeData.weekInYear;
        }
        data.reportType=window.parent.workMode.toUpperCase();
        var categories = data.categories;
        if(!Array.isArray(categories)){
            data.categories = [categories];
        }
        var pager = {page:page,size:size};
        if(!size){
            pager['page']= 1;
            pager['size'] = $("#datagrid").datagrid("getPager").pagination("options").pageSize||100;
        }
        var jsonobj = {};
        jsonobj.entityStatus = $("#entityStatus").switchbutton("options").checked==true?"OK":"DISABLE";
        jsonobj = $.extend(true,jsonobj,transfer(data));
        jsonobj = JSON.stringify(jsonobj);
        $.ajax({
            url:config.url + "/reference/page?"+transfer2url(pager),
            type:'post',
            data:jsonobj,
            contentType:"application/json;charset=UTF-8",
            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function () {
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"数据加载中..."
                });
            },
            complete:function () {
                $.messager.progress("close");
            },
            success:function (data) {
                $.messager.progress("close");
                if(data){
                    globalData = data;
                    $("#datagrid").datagrid("loadData",data);
                    dtd.resolve();
                }
            },
            error:function (XMLHttpRequest,textStatus,errorThrown) {

            }
        });
        return dtd.promise();
    }
    $("#ff").keydown(function (event) {
        var e = event || window.event;
        var keyCode = e.keyCode || e.which;
        if(keyCode=="13"){
            searchBy();
        }
    });
</script>
<script type="text/javascript">
    function actions(val, row){
        var disableBtnText = row.entityStatus=='OK'?'禁用':"启用";
        return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
            "style='width:50px;' onclick='edit(\""+row.id+"\",\""+row.categoryCode+"\")'>修改</a>&nbsp;&nbsp;"+
            "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:50px;' onclick='updateStatus(\""+row.id+"\", \"" + row.entityStatus + "\")'>"+disableBtnText+"</a>";
    }
    function edit(id){
        window.parent.addTab("修改比例", "/webapp/pages/channel/avcReference/add.html?id="+id);
    }
    function updateStatus(id,entityStatus){
        $.messager.confirm("提示","您确定禁用/启用吗？",function (f) {
            if(f){
                $.ajax({
                    url:config.url+"/reference/"+id,
                    type:"DELETE",
                    dataType:"json",
                    data:JSON.stringify(id),
                    contentType:"application/json;charset=UTF-8",
                    xhrFields:{withCredentials:true},
                    beforeSend:function () {
                        $.messager.progress({
                            title:"请稍等",
                            interval:50,
                            text:"操作进行中..."
                        });
                    },
                    complete:function () {
                        $.messager.progress("close");
                        $.messager.alert("提示","操作成功","info",function () {
                            searchBy(1,100);
                        });
                    },
                    success:function (data) {
                        $.messager.alert("提示","操作成功","info",function () {
                            searchBy(1,100);
                        });
                    },
                    error:function (data) {

                    }
                });
            }
        });
    }
    /*上传文件from的方式*/
    $(function() {
        $("#subr").click(function () {
            // var form = new FormData(document.getElementById("file_form"));
            // alert(form);
            $("#file_formr").ajaxSubmit({
                xhrFields:{withCredentials:true},
                url:config.url +"/reference/referencelUpload",
                type:"POST",
                dataType : "json",
                data:$('#file_formr').serialize(),
                processData: false,
                beforeSend:function () {
                    $.messager.progress({
                        title:"请稍等",
                        interval:20,
                        text:"操作进行中..."
                    });
                },
                complete:function () {
                    $.messager.progress("close");
                },
                success : function(data) {
                    if(data.code=="200"){
                        $("#referencejg").window("open");
                        document.getElementById("messagetext").innerText=data.msg;
                        // alert(data.msg);
                    }else {
                        $.messager.alert("提示", message.msg, "info");
                    }
                }
            })
        })
    });
    function clickHandler() {
        // alert("onclick attribute in html");
        $("#referencejg").window("close");
        $("#upmall").window("close");
        searchBy();
    }

    function OnlineCount(){
        var formData = getFormData(document.getElementById("ff"));
        if (!isMonthType() && !formData.week) {
            formData.week = window.parent.timeData.weekInYear;
        }
        var categories = formData.categories;
        if(!Array.isArray(categories)){
            formData.categories = [categories];
        }
        formData.reportType=window.parent.workMode.toUpperCase();
        var jsonobj = {};
        jsonobj = $.extend(true,jsonobj,transfer(formData));
        jsonobj = JSON.stringify(jsonobj);
        $.ajax({
            url:config.url+"/reference/OnlineCount",
            type:"POST",
            data:jsonobj,
            contentType:"application/json;charset=UTF-8",
            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function(){
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"操作进行中..."
                });
            },
            complete:function(){
                $.messager.progress("close");
            },
            success:function(data){
                if(data.code == 200){
                    $.messager.alert("提示",data.msg,"info",function(){
                        // window.parent.closeCurrentTab(true);
                        // $('#filling').form('clear');放到了页面打开前
                        $('#addModelNone').dialog('close');
                        searchBy();
                    });
                }else{
                    $.messager.alert("错误",data.msg,"error");
                }
            },
            error:function(XMLHttpRequest,textStatus,thrown){
                $.messager.alert("提示","操作失败","error");
            }
        });
        return false;
    }

    /**
     * 重新计算部分系数
     * @returns {boolean}
     */
    function jsReference(){
        var formData = getFormData(document.getElementById("ff"));
        if (!isMonthType() && !formData.week) {
            formData.week = window.parent.timeData.weekInYear;
        }
        var categories = formData.categories;
        if(!Array.isArray(categories)){
            formData.categories = [categories];
        }
        formData.reportType=window.parent.workMode.toUpperCase();
        var jsonobj = {};
        jsonobj = $.extend(true,jsonobj,transfer(formData));
        jsonobj = JSON.stringify(jsonobj);
        $.ajax({
            url:config.url+"/reference/jsReference",
            type:"POST",
            data:jsonobj,
            contentType:"application/json;charset=UTF-8",
            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function(){
                $.messager.progress({
                    title:"请稍等",
                    interval:80,
                    text:"操作进行中..."
                });
            },
            complete:function(){
                $.messager.progress("close");
            },
            success:function(data){
                if(data.code == 200){
                    $.messager.alert("提示",data.msg,"info",function(){
                        $('#addModelNone').dialog('close');
                        searchBy();
                    });
                }else{
                    $.messager.alert("错误",data.msg,"error");
                }
            },
            error:function(XMLHttpRequest,textStatus,thrown){
                $.messager.alert("提示","操作失败","error");
            }
        });
        return false;
    }
    /**
     * 系数重置
     * @returns {boolean}
     */
    function xsReset(){
        var formData = getFormData(document.getElementById("ff"));
        if (!isMonthType() && !formData.week) {
            formData.week = window.parent.timeData.weekInYear;
        }
        var categories = formData.categories;
        if(!Array.isArray(categories)){
            formData.categories = [categories];
        }
        formData.reportType=window.parent.workMode.toUpperCase();
        var jsonobj = {};
        jsonobj = $.extend(true,jsonobj,transfer(formData));
        jsonobj = JSON.stringify(jsonobj);
        $.ajax({
            url:config.url+"/reference/xsReset",
            type:"POST",
            data:jsonobj,
            contentType:"application/json;charset=UTF-8",
            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function(){
                $.messager.progress({
                    title:"请稍等",
                    interval:80,
                    text:"操作进行中..."
                });
            },
            complete:function(){
                $.messager.progress("close");
            },
            success:function(data){
                if(data.code == 200){
                    $.messager.alert("提示",data.msg,"info",function(){
                        $('#addModelNone').dialog('close');
                        searchBy();
                    });
                }else{
                    $.messager.alert("错误",data.msg,"error");
                }
            },
            error:function(XMLHttpRequest,textStatus,thrown){
                $.messager.alert("提示","操作失败","error");
            }
        });
        return false;
    }

    function formatBrand(val, row) {
        return row.brandName + '(' + row.brandCode + ')';
    }
    function formatCategory(val, row) {
        return row.categoryName + '(' + row.categoryCode + ')';
    }

    /**
     * 修改电商销量
     */
    function clCount() {
        var param = getFormData(document.getElementById("ff"));
        param.reportType=window.parent.workMode.toUpperCase();
        var categories = param.categories;
        $.ajax({
            url:config.url+"/reference/clCount",
            type:"get",
            data:transfer(param),
            contentType:"application/json;charset=UTF-8",
            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function(){
                $.messager.progress({
                    title:"请稍等",
                    interval:80,
                    text:"操作进行中..."
                });
            },
            complete:function(){
                $.messager.progress("close");
            },
            success:function(data){
                if(data.code == 200){
                    $.messager.alert("提示",data.msg,"info",function(){
                        $('#addModelNone').dialog('close');
                    });
                }else{
                    $.messager.alert("错误",data.msg,"error");
                }
            },
            error:function(XMLHttpRequest,textStatus,thrown){
                $.messager.alert("提示","操作失败","error");
            }
        });
    }

    /**
     * 恢复电商销售销量
     */
    function restoreCount() {
        var param = getFormData(document.getElementById("ff"));
        param.reportType=window.parent.workMode.toUpperCase();
        var categories = param.categories;
        $.ajax({
            url:config.url+"/reference/restoreCount",
            type:"get",
            data:transfer(param),
            contentType:"application/json;charset=UTF-8",
            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function(){
                $.messager.progress({
                    title:"请稍等",
                    interval:80,
                    text:"操作进行中..."
                });
            },
            complete:function(){
                $.messager.progress("close");
            },
            success:function(data){
                if(data.code == 200){
                    $.messager.alert("提示",data.msg,"info",function(){
                        $('#addModelNone').dialog('close');
                    });
                }else{
                    $.messager.alert("错误",data.msg,"error");
                }
            },
            error:function(XMLHttpRequest,textStatus,thrown){
                $.messager.alert("提示","操作失败","error");
            }
        });
    }
</script>
</html>
